package cn.tedu.medicalpath.inspection.controller;

import cn.tedu.medicalpath.base.response.JsonResult;
import cn.tedu.medicalpath.inspection.pojo.dto.InspectionSaveParam;
import cn.tedu.medicalpath.inspection.pojo.dto.SubInspectionDeleteParam;
import cn.tedu.medicalpath.inspection.pojo.dto.SubInspectionEditParam;
import cn.tedu.medicalpath.inspection.pojo.dto.UnInspectedItemQuery;
import cn.tedu.medicalpath.inspection.pojo.vo.SubInspectionVO;
import cn.tedu.medicalpath.inspection.pojo.vo.UnInspectedItemVO;
import cn.tedu.medicalpath.inspection.service.InspectionService;
import cn.tedu.medicalpath.inspection.service.SubInspectionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("v1/inspection")
public class InspectionController {
    @Autowired
    InspectionService inspectionService;
    @Autowired
    SubInspectionService subInspectionService;

    @PostMapping("update")
    public JsonResult update(@RequestBody InspectionSaveParam inspectionSaveParam) {
        log.debug("开始处理【更新检查单】的请求，参数：{}", inspectionSaveParam);
        inspectionService.updateById(inspectionSaveParam);
        return JsonResult.success();
    }
    @GetMapping("query/{id}")
    public JsonResult query(@PathVariable Long id) {
        log.debug("开始处理【查询检查单】的请求，参数：{}", id);
        SubInspectionVO subInspectionVO=inspectionService.queryById(id);
        return JsonResult.success(subInspectionVO);
    }
    @GetMapping("select/{id}")
    public JsonResult select(@PathVariable Long id) {
        log.debug("开始处理【查询检查项】的请求，参数：{}", id);
        List<SubInspectionVO> list =  subInspectionService.selectById(id);
        return JsonResult.success(list);
    }
    @GetMapping("selectOne/{inspectionItemId}/{inspectionId}")
    public JsonResult selectOne(@PathVariable Long inspectionItemId,@PathVariable Long inspectionId) {
        log.debug("开始处理【查询单个检查项】的请求，参数：{},{}", inspectionItemId, inspectionId);
        SubInspectionVO subInspectionVO = subInspectionService.selectOneById(inspectionItemId,inspectionId);
        return JsonResult.success(subInspectionVO);
    }
    @PostMapping("edit")
    public JsonResult edit(SubInspectionEditParam subInspectionEditParam) {
        log.debug("开始处理【编辑检查项】的请求，参数：{}", subInspectionEditParam);
        subInspectionService.edit(subInspectionEditParam);
        return JsonResult.success();
    }
    @PostMapping("insert")
    public JsonResult insert(SubInspectionEditParam subInspectionEditParam) {
        log.debug("开始处理【新增检查单】的请求，参数：{}", subInspectionEditParam);
        subInspectionService.insert(subInspectionEditParam);
        return JsonResult.success();
    }
    @PostMapping("delete")
    public JsonResult delete(SubInspectionDeleteParam subInspectionDeleteParam) {
        log.debug("开始处理【删除检查项】的请求，参数：{}", subInspectionDeleteParam);
        subInspectionService.delete(subInspectionDeleteParam);
        return JsonResult.success();
    }

    @GetMapping("/selectUnInspected")
    public JsonResult selectUnInspectedItem(UnInspectedItemQuery unInspectedItemQuery) {
        log.debug("开始处理【查询未检查的检查项】的请求，入参：{}", unInspectedItemQuery);
        List<UnInspectedItemVO> unInspectedItemVOList
                = subInspectionService.selectUnInspectedItem(unInspectedItemQuery);
        log.debug("【查询未检查的检查项】成功，入参：{}，出参：{}"
                  , unInspectedItemQuery, unInspectedItemVOList);
        return JsonResult.success(unInspectedItemVOList);
    }


}
